package mx.com.deckosys.utils;

import java.awt.event.FocusAdapter;

import javax.swing.SwingUtilities;

public class FullSelectorListener extends FocusAdapter {

	public FullSelectorListener() {
	}
	@Override
	
	public void focusLost(java.awt.event.FocusEvent evt) {

	}

	@Override
	public void focusGained(java.awt.event.FocusEvent evt) {
		final Object o = evt.getSource();
		if(o instanceof javax.swing.JTextField){
			javax.swing.JTextField txt = (javax.swing.JTextField) o;
			txt.setSelectionStart(0);
			txt.setSelectionEnd(txt.getText().length());
		}else if(o instanceof javax.swing.JFormattedTextField){
			SwingUtilities.invokeLater( new Runnable() {
                @Override
                public void run() {                                                              
                        ((javax.swing.JFormattedTextField)o).selectAll();
                }
			});
		}
	}
} 
